var baseURL = "http://localhost:7001";
import axios from 'axios';
axios.defaults.withCredentials = true; //前端跨域传递Cookie设置 

import store from '../store/index'
// 添加请求拦截器
axios.interceptors.request.use(function (config) {
    // 在发送请求之前做些什么
    store.state.isLoading = true;
    return config;
});
// 添加响应拦截器
axios.interceptors.response.use(function (response) {
    // 对响应数据做点什么
    store.state.isLoading = false;
    return response;
});

function http({
    method,
    url,
    data,
}){
    console.log(baseURL+url);
    return new Promise((resolve,reject)=>{
        axios({
            method,
            url: baseURL+url,
            data,
        }).then((res)=>{
            resolve(res);
        }).catch((res)=>{
            reject(res);
        })
    })
}
export default http;